/*
	NMS for jQuery
	
	(c) Steven Monetti 2008
	
	E-Mail: steven.monetti@gmail.com	
	
	V 1.0 - Dec 27th

*/

(function($){  
var init = false;
$.fn.nms_msg = function(options) {  
	
	//Options
	var defaults = {  
		text: '',
		text_color: '#333',
		text_align: 'center',
		border_color: '',
		background: '',
		freeze: false,
		close: true,
		delay: '',
		icon: '',
		icon_path: 'NMS/ico/'  
	};  
	var options = $.extend(defaults, options);  
			
	//-- Functionality --- //
		
		//--- Message box --- //
		
		//Style overwrite
		var style='', icon='', close='';
		if(options.border_color != '') style += 'border: 3px solid ' + options.border_color +';';
		if(options.background != '')   style += 'background: ' + options.background +';';
		if(options.close) close = '<div id="nms_msg_close"></div>';
		else					close = '<div id="nms_msg_close" style="display: none"></div>';
		//Message with/without loading
		if(options.icon != '') icon = '<td width="1"><img src="'+options.icon_path + options.icon+'"></td>';

		
		//Box HTML
		var content = '\
		<div class="content" style="'+style+'"> \
			'+close+'\
			<table>\
				<tr>\
					'+icon+'\
					<td style="vertical-align: middle;"> \
						<div class="text" style="text-align: '+options.text_align+'; color:'+options.text_color+';">'+options.text+'</div> \
					</td> \
				</tr>\
			</table>\
		</div>';
		
		var box='\
		<div id="nms_msg" style="display: none;">\
			<div class="popup">\
			'+content+'\
			</div>\
		</div>';
			
		//Appened to body and show
		if(!init) { 
			$(this).append(box);
			init = true;
		}
		else {	
			$('#nms_msg .content').remove();
			$('#nms_msg .popup').append(content);
		}
		
		if(options.freeze) $(this).append('<div id="nms_freezeBG" style="display: none;"></div>');
		$('#nms_msg').fadeIn('normal');
		if(options.freeze) $('#nms_freezeBG').fadeIn('normal');
	
		//Hide with delay
		if(options.delay != '') 
		{
			$('#nms_msg').fadeTo(options.delay, 1).fadeOut('slow');
			$('#nms_freezeBG').fadeTo(options.delay, 0.4).fadeOut('slow');
		}
		
		//Close function
		$('#nms_msg_close').bind('click', function () {
			$('#nms_msg').fadeOut('slow');
			$('#nms_freezeBG').fadeOut('slow');
		});
		
		
}


})(jQuery);  